﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Common.Core.HttpHandler
{
    /// <summary>
    /// ajax请求基类于逻辑无关的，具体业务请在Common.Facade.dll组件里实现
    /// </summary>
    public abstract class AjaxHandler : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            // 如果无法为其他请求重用托管处理程序，则返回 false。
            // 如果按请求保留某些状态信息，则通常这将为 false。
            get { return true; }
        }

        public virtual string ContengType
        {
            get { return "text/html"; }
        }

        /// <summary>
        /// 具体的业务实现
        /// </summary>
        /// <returns></returns>
        public abstract string GetBusinessData();

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.ContentType = ContengType;

            AjaxMappingAttribute.Bind(this, context.Request.Params);

            context.Response.Output.Write(GetBusinessData());
            context.Response.End();
        }

        #endregion
    }
}
